package main

import (
	"financial/application/blockchain"
	"financial/application/controller"
	"github.com/gin-gonic/gin"
	"net/http"
)

func setupRouter() *gin.Engine  {
	router := gin.Default()

	// 中间件
	router.Use(controller.CORS)
	router.Use(controller.FixVueRouter)

	// 加载中间件
	router.Use(controller.CORS)         // 先加载跨域模块（便于开发）
	router.Use(controller.FixVueRouter) // 修复前端内部路由问题

	router.GET("/QueryRoleVacunas/:id", controller.QueryRoleVacunas)

	router.POST("/createVacuna", controller.CreateVacuna)
	router.POST("/createOrder", controller.CreateOrder)

	// 静态文件路由
	router.StaticFS("/web/", http.Dir("./public/"))

	return router
}

func main()  {
	blockchain.Init()
	router := setupRouter()
	err := router.Run()
	if err != nil {
		panic(err)
	}
}
